package com.homelink.android.explorerup.component;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.util.Log;

import com.homelink.android.explorerup.R;

public class Dialog {
	public static final String TAG = "Dialog";
	public static final int MENU_INDEX_COPY = 0;
	public static final int MENU_INDEX__PASTE = 1;
	public static final int MENU_INDEX__DELETE = 2;
	public static final int MENU_INDEX_RENAME = 3;
	public static final int MENU_INDEX_CUT = 4;
	
	public static android.app.Dialog createInputDialog(Context ctx){
		AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
		builder.setTitle(R.string.title_enter_name);
		
		android.app.Dialog dialog = new android.app.Dialog(ctx);
		dialog.setContentView(R.layout.newfiles);
		dialog.setTitle(R.string.title_enter_name);
		
		return dialog;
	}
	
	public static AlertDialog createConfirmExitDialog(Context ctx, final Dialog.Listener l){
		AlertDialog.Builder builder = new Builder(ctx);
		builder.setMessage(R.string.msg_confirm_exit);
		builder.setTitle(R.string.title_confir_exit);
		builder.setPositiveButton(R.string.btn_exit, new OnClickListener() {
			
			public void onClick(DialogInterface dialog, int which) {
				dialog.dismiss();
				l.onExit();
				
			}
		});
		
		builder.setNeutralButton(R.string.btn_cancel,null);
		return builder.create();
	}
	
	public static AlertDialog createContextMenuChoiceDialog(Context ctx,final int selectedItemIndex,final Dialog.Listener l){
		AlertDialog.Builder builder = new Builder(ctx);
		
		builder.setTitle(R.string.title_select);
		String [] menus = ctx.getResources().getStringArray(R.array.item_context_menus);
		Log.d(TAG, String.valueOf(menus.length));
	
		builder.setItems(menus,  new DialogInterface.OnClickListener(){
			public void onClick(DialogInterface dialog, int which) {
				if(l != null){
					switch(which){
					case MENU_INDEX__DELETE:
						l.onDelete(selectedItemIndex);
						break;
					case MENU_INDEX__PASTE:
						l.onPaste(selectedItemIndex);
						break;
					case MENU_INDEX_COPY:
						l.onCopy(selectedItemIndex);
						break;
					case MENU_INDEX_CUT:
						l.onCut(selectedItemIndex);
						break;
					case MENU_INDEX_RENAME:
						l.onRename(selectedItemIndex);
						break;
				
					}
				}
				
			}
			
		});
		return builder.create();
		
		
		
	}

	
	public static interface Listener{
		public void onExit();
		public void onCopy(int index);
		public void onPaste(int index);
		public void onMove(int index);
		public void onRename(int index);
		public void onDelete(int index);
		public void onCut(int index);
	}
}
